/*
 *  xmlHandler.h
 *  initiativeTracker
 *
 *  Created by Sam Jaffe on 5/9/12.
 *  Copyright 2012 WPI. All rights reserved.
 *
 */

#pragma once

#include <string>
#include <unordered_map>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>

class XML_Handler {
private:
    xercesc::XercesDOMParser parser;
public:
    XML_Handler();
    XML_Handler(const std::string schema);
    ~XML_Handler();
    void parse(const std::string xml);
    xercesc::DOMDocument* getDocument();
};

template <class T, class S, class R0, class R1, class Q>
class XML_IO_Controller {
protected:
    XML_Handler* handler;
    std::unordered_map<std::string, R1 (*) (T, Q) > responseMap;
public:
    XML_IO_Controller() {}
    XML_IO_Controller(std::string schema) {
        handler = new XML_Handler(schema);
    }
    ~XML_IO_Controller() {}
    virtual R0 process(T target, S source, std::string xmlMessage) = 0;
    virtual R0 recieve(T target, Q xmlMessage) = 0;
    virtual void send(S source, std::string xmlMessage) = 0;
    virtual void init() = 0;
    void emplace(std::string key, R1 (*fun)(T, Q)) {
        responseMap.emplace(key, fun);
    }
};
